package lambad.demo01;

/**
 * @author 真香
 * @create 2021-04-11 15:12
 */
public class Java8LambdaTest {

    public static void main(String[] args) {

        Java8LambdaTest lambdaTest = new Java8LambdaTest();

        // 类型声明    加
        MathOperation addition = (int a, int b) -> a + b;

        // 不用声明类型  减
        MathOperation subtraction =(a, b) -> a-b;

        // 大括号中的返回语句  乘
        MathOperation multiplication = (a,b) -> {return  a * b ;};

        // 没有大括号和返回语句  除
        MathOperation division = (a,b) -> a / b;

        System.out.println("10 + 5 = " + lambdaTest.operate(10, 5, addition));
        System.out.println("10 - 5 = " + lambdaTest.operate(10, 5, subtraction));
        System.out.println("10 x 5 = " + lambdaTest.operate(10, 5, multiplication));
        System.out.println("10 / 5 = " + lambdaTest.operate(10, 5, division));


        // 不用括号
        GreetingService greetingService1 = message ->
                System.out.println("hello"+message);

        // 用括号
        GreetingService greetingService2 = (message) ->
                System.out.println("hello"+message);

        greetingService1.sayMessage("Lucy");
        greetingService2.sayMessage("Jack");



    }

    // 类型
    interface MathOperation {
        int operation(int a, int b);
    }



    // 类型
    interface GreetingService {
        void sayMessage(String message);
    }



    // 方法
    private int operate(int a, int b, MathOperation mathOperation){
        return mathOperation.operation(a, b);
    }

}
